package com.hileto.inf.utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;


/**
 * Copyright: Copyright (c) 2012
 *     深圳市海乐淘电子商务有限公司
 * @Author : 曾林宝
 * @CreateTime : 2013-1-21 上午10:21:09
 *
 * @Description: 转json工具类.
 */
public class JsonHelp {

	/**
	 * @Description : json序列化带类名.
	 * @Author : 曾林宝
	 * @CreateTime : 2013-1-21 上午10:21:22
	 * @param object
	 * @return
	 */
	public static String object2JsonSerializer(Object object){
		String result = null;
		if(!ObjectHelp.isEmpty(object)){
			result = JSON.toJSONString(object, SerializerFeature.WriteClassName);
		}
		return result;
	}
	
	/**
	 * @Description : json反序列化带类名.
	 * @Author : 曾林宝
	 * @CreateTime : 2013-1-21 上午10:21:22
	 * @param object
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public static <T> T json2ObjectSerializer(String json){
		T result = null;
		if(ObjectHelp.isNotEmpty(json)){
			result = (T) JSON.parse(json);
		}
		return result;
	}

	public static String object2Json(Object object) {
		String result = null;
		if(!ObjectHelp.isEmpty(object)){
			result = JSON.toJSONString(object);
		}
		return result;
	}
	public static String json2Object(Object object) {
		String result = null;
		if(!ObjectHelp.isEmpty(object)){
			result = JSON.toJSONString(object);
		}
		return result;
	}
	
}
